package com.zut.domain.sevice.impl;
import com.zut.auth.infra.entity.AuthRole;
import com.zut.auth.infra.service.AuthRoleService;
import com.zut.common.enums.IsDeletedFlagEnum;
import com.zut.common.enums.StatusFlagEnum;
import com.zut.domain.convert.AuthRoleBOConverter;
import com.zut.domain.entity.AuthRoleBO;
import com.zut.domain.sevice.AuthRoleDomainService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {


    @Resource
    private AuthRoleService authRoleService;

    //注册角色
    @SneakyThrows
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole= AuthRoleBOConverter.INSTANCE.ConvertBOTo(authRoleBO);
        authRole.setIsDelete(IsDeletedFlagEnum.UN_DELETED.getCode());
        authRole.setStatus(StatusFlagEnum.ENABLE.getCode());
        int insert = authRoleService.insert(authRole);
        return insert>0;
    }

    //更改角色信息
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.ConvertBOTo(authRoleBO);
        int update = authRoleService.update(authRole);
        return update>0;
    }

    //删除角色
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleBOConverter.INSTANCE.ConvertBOTo(authRoleBO);
       authRole.setIsDelete(IsDeletedFlagEnum.DELETED.getCode());
        int update = authRoleService.update(authRole);
        return update>0;
    }


}
